import http from '@/plugins/aixos'
import { SectionDtoModel, SectionModel } from '@/types/model'

export const findSection = async (data: number) => {
  return http.request<SectionModel>({
    url: '/section/' + data,
    method: 'GET',
  })
}

export function addSection(data: SectionDtoModel) {
  return http.request<SectionModel>({
    url: '/section',
    method: 'POST',
    data,
  })
}

export async function findAllSection(args: Record<string, any>) {
  const url =
    '/section?' +
    Object.entries(args)
      .map(([key, value]) => `${key}=${value}`)
      .join('&')
  return http.request<SectionModel[]>({
    url,
    method: 'GET',
  })
}

export async function delSection(id: number) {
  return http.request<SectionModel>({
    url: '/section/' + id,
    method: 'DELETE',
  })
}

export async function updateSection(id: number, data: any) {
  return http.request<SectionModel>({
    url: '/section/' + id,
    method: 'PATCH',
    data,
  })
}

export const caclSection = async (args = {}) => {
  const url =
    '/section/calc?' +
    Object.entries(args)
      .map(([key, value]) => `${key}=${value}`)
      .join('&')
  return http.request({
    url,
    method: 'GET',
  })
}

export function calcTowerPointsSection(args = {}) {
  const url =
    '/section/calc/towerPoints?' +
    Object.entries(args)
      .map(([key, value]) => `${key}=${value}`)
      .join('&')
  return http.request({
    url,
    method: 'GET',
  })
}
